﻿/**
 * CJDisplay
 *
 * @author		Allen Chou
 * @version		1.0.0 (last update: Dec 8 2008)
 * @link        http://cjcat.blogspot.com
 * @link		http://cjcat2266.deviantart.com
 */

package idv.cjcat.display {
	import flash.display.*;
	import flash.errors.IllegalOperationError;

	/**
	 * The <code>CJDisplay</code> class provides shortcuts to applying <code>LineStyle</code> and <code>Fill</code> to a <code>Shape</code> or <code>Sprite</code>.
	 * 
	 * @example
	 * <listing>
	 * import idv.cjcat.display.*;
	 * 
	 * var lineStyle:LineStyle = new LineStyle();
	 * var fill:Fill = new Fill();
	 * 
	 * //these two lines are equivalent
	 * clip_mc.graphics.lineStyle(lineStyle.thickness, lineStyle.color, lineStyle.alpha, lineStyle.pixelHinting, lineStyle.scaleMode, lineStyle.caps, lineStyle.joints, lineStyle.miterLimit);
	 * CJDisplay.lineStyle(clip_mc, lineStyle);
	 * 
	 * //these two lines are equivalent
	 * clip_mc.graphics.beginFill(fill.color, fill.alpha);
	 * CJDisplay.beginFill(clip_mc, fill);</listing>
	 */
	public class CJDisplay {
		
		/**
		 * Sets the line style of the <code>graphics</code> property of a <code>Shape</code> or <code>Sprite</code>.
		 * @param	obj    The <code>Shape</code> or <code>Sprite</code>.
		 * @param	style  The line style.
		 */
		public static function lineStyle(obj:*, style:LineStyle):void {
			if (obj is Shape) {
				Shape(obj).graphics.lineStyle(style.thickness, style.color, style.alpha, style.pixelHinting, style.scaleMode, style.caps, style.joints, style.miterLimit);
				return;
			}
			if (obj is Sprite) {
				Sprite(obj).graphics.lineStyle(style.thickness, style.color, style.alpha, style.pixelHinting, style.scaleMode, style.caps, style.joints, style.miterLimit);
				return;
			}
			throw new IllegalOperationError("The object has no such property as graphics.");
		}
		
		/**
		 * Sets the fill to be used by the <code>graphics</code> property of a <code>Shape</code> or <code>Sprite</code>.
		 * @param	obj   The <code>Shape</code> or <code>Sprite</code>.
		 * @param	fill  The fill.
		 */
		public static function beginFill(obj:*, fill:Fill):void {
			if (obj is Shape) {
				Shape(obj).graphics.beginFill(fill.color, fill.alpha);
				return;
			}
			if (obj is Sprite) {
				Sprite(obj).graphics.beginFill(fill.color, fill.alpha);
				return;
			}
			throw new IllegalOperationError("The object has no such property as graphics.");
		}
		
	}
}